package com.quanyan.place.web;

import com.quanyan.api.APIResponse;
import com.quanyan.orderpay.response.RespPreOrder;
import com.quanyan.place.entity.TbBizPlaceStatement;
import com.quanyan.place.entity.apireq.*;
import com.quanyan.place.entity.apiresp.RespCreateStatement;
import com.quanyan.place.entity.apiresp.RespSaveTransferRemark;
import com.quanyan.place.entity.apiresp.RespTransferStatement;
import com.quanyan.place.service.PlaceBizSettleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * Created by yuanxuebing on 16-10-21.
 */
@RestController
@RequestMapping(value = "/admin/api/place/financial/placeBizSettle")
public class PlaceBizSettleController {

    private static final Logger logger = LoggerFactory.getLogger(PlaceBizSettleController.class);

    @Autowired
    private PlaceBizSettleService placeBizSettleService;

    @RequestMapping(value = "/listUnSettleOrders", method = RequestMethod.POST)
    public APIResponse<?> listUnSettleOrders(@RequestBody ReqListUnSettleOrders reqListUnSettleOrders) {
        try {
            return APIResponse.returnSuccess(placeBizSettleService.listUnSettleOrders(reqListUnSettleOrders));
        }catch (Exception e){
            logger.error("{}",e);
            return  APIResponse.returnFail("系统异常");
        }
    }

    @RequestMapping(value = "/createStatement", method = RequestMethod.POST)
    public APIResponse<?> createStatment(@RequestBody ReqCreateStatement reqCreateStatement) {
        try {
             placeBizSettleService.createStatement();
           return APIResponse.returnSuccess();
        }catch (Exception e){
            logger.error("{}",e);
            return  APIResponse.returnFail("系统异常："+ e.toString());
        }
    }


    @RequestMapping(value = "/listPlaceStatements", method = RequestMethod.POST)
    public APIResponse<?> listPlaceStatements(@RequestBody ReqListPlaceStatements reqListPlaceStatements) {
        try {
            return APIResponse.returnSuccess(placeBizSettleService.listPlaceStatements(reqListPlaceStatements));
        }catch (Exception e){
            logger.error("{}",e);
            return  APIResponse.returnFail("系统异常");
        }
    }


    @RequestMapping(value = "/getStatementInfo", method = RequestMethod.POST)
    public APIResponse<?> getStatementInfo(@RequestBody ReqGetStatementInfo reqGetStatementInfo) {
        try {
            return APIResponse.returnSuccess(placeBizSettleService.getStatementInfo(reqGetStatementInfo));
        }catch (Exception e){
            logger.error("{}",e);
            return  APIResponse.returnFail("系统异常");
        }
    }


    @RequestMapping(value = "/saveTransferRemark", method = RequestMethod.POST)
    public APIResponse<?> saveTransferRemark(@RequestBody ReqSaveTransferRemark reqSaveTransferRemark) {
        try {
            RespSaveTransferRemark result = placeBizSettleService.saveTransferRemark(reqSaveTransferRemark);
            if (result == null) {
                return APIResponse.returnFail("响应为空！");
            }

            if (result.getErrorMsg() != null) {
                return APIResponse.returnFail(result.getErrorMsg());
            }

            return APIResponse.returnSuccess(result);
        }catch (Exception e){
            logger.error("{}",e);
            return  APIResponse.returnFail("系统异常："+ e.toString());
        }
    }


    @RequestMapping(value = "/transferStatement", method = RequestMethod.POST)
    public APIResponse<?> transferStatement(@RequestBody ReqTransferStatement reqTransferStatement) {
        try {
            RespTransferStatement result = placeBizSettleService.transferStatement(reqTransferStatement);
            if (result == null) {
                return APIResponse.returnFail("响应为空！");
            }

            if (result.getErrorMsg() != null) {
                return APIResponse.returnFail(result.getErrorMsg());
            }

            return APIResponse.returnSuccess(result);
        }catch (Exception e){
            logger.error("{}",e);
            return  APIResponse.returnFail("系统异常："+ e.toString());
        }
    }


    @RequestMapping(value = "/cashForScanTransfer", method = RequestMethod.POST)
    public APIResponse<?> cashForScanTransfer(@RequestBody TbBizPlaceStatement reqTransferStatement) {
        try {
            APIResponse<RespPreOrder> result = placeBizSettleService.cashForScanTransfer(reqTransferStatement,null,null);
            if (result == null) {
                return APIResponse.returnFail("响应为空！");
            }
            return APIResponse.returnSuccess(result);
        }catch (Exception e){
            logger.error("{}",e);
            return  APIResponse.returnFail("系统异常："+ e.toString());
        }
    }
}